package com.multimedia.scala.euler
/*
If the numbers 1 to 5 are written out in words: one, two, three,
four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were
written out in words, how many letters would be used?


NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two)
contains 23 letters and 115 (one hundred and fifteen) contains 20 letters.
The use of "and" when writing out numbers is in compliance with British usage.
 */
object Asd17 {
  def main(args : Array[String]) : Unit = {
    val simpleDigits =
      List("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
      "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
      .zipWithIndex.map{case (i, e)=>{(e, i)}}
      .toMap+{20->"twenty"}+{30->"thirty"}+{40->"forty"}+{50->"fifty"}+{60->"sixty"}+{70->"seventy"}+
      {80->"eighty"}+{90->"ninety"}+{1000->"onethousand"}
    val hundreds = (1 to 9).map(simpleDigits(_)+"hundred").zipWithIndex.map{case (e, i)=>((i+1)*100, e)}.toMap
    val belowHundred = (21 to 99).filterNot(_%10==0).map(e => {
      var e2 = (e/10)*10 
      var e1 = e%10
      (e, simpleDigits(e2)+simpleDigits(e1))
    })
    var digits = hundreds++simpleDigits++belowHundred
    var belowThousand = (101 to 999).filterNot(_%100==0).map(e => {
      var e3 = (e/100)*100
      var e1 = e%100
      (e, digits(e3)+"and"+digits(e1))
    })
    digits ++= belowThousand
    //digits.filter(i=>{i._1%100==0}).foreach(println)
    digits.filter(i=>{i._1%100!=0&&i._1%10==0}).foreach(println)
    print(
	    (1 to 1000).map(digits).map(_.size)
	    //.foreach(print)
	    .reduce(_ + _)
    )
  }

}
